
package com.anjiplus.template.gaea.business.modules.httpdir.controller;

import com.anji.plus.gaea.annotation.Permission;
import com.anji.plus.gaea.annotation.log.GaeaAuditLog;
import com.anji.plus.gaea.bean.ResponseBean;
import com.anji.plus.gaea.curd.controller.GaeaBaseController;
import com.anji.plus.gaea.curd.service.GaeaBaseService;
import com.anji.plus.gaea.holder.UserContentHolder;
import com.anji.plus.gaea.utils.GaeaUtils;
import com.anjiplus.template.gaea.business.modules.httpdir.controller.dto.HttpDirDto;
import com.anjiplus.template.gaea.business.modules.httpdir.controller.param.HttpDirParam;
import com.anjiplus.template.gaea.business.modules.httpdir.dao.entity.HttpDir;
import com.anjiplus.template.gaea.business.modules.httpdir.service.HttpDirService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Raod
 * @desc 数据集 controller
 * @website https://gitee.com/anji-plus/gaea
 * @date 2021-03-18 12:11:31.150755900
 **/
@RestController
@RequestMapping("/httpDir")
public class HttpDirController extends GaeaBaseController<HttpDirParam, HttpDir, HttpDirDto> {

    @Autowired
    private HttpDirService httpDirService;

    @Override
    public GaeaBaseService<HttpDirParam, HttpDir> getService() {
        return httpDirService;
    }

    @Override
    public HttpDir getEntity() {
        return new HttpDir();
    }

    @Override
    public HttpDirDto getDTO() {
        return new HttpDirDto();
    }

    @GetMapping("/detailBysetId/{id}")
    @Permission(code = "query", name = "明细")
    public ResponseBean detailBysetId(@PathVariable("id") String id) {
        this.logger.info("{}根据ID查询服务开始，id为：{}", this.getClass().getSimpleName(), id);
        ResponseBean responseBean = this.responseSuccessWithData(httpDirService.detailSetById(id));
        this.logger.info("{}根据ID查询结束，结果：{}", this.getClass().getSimpleName(), GaeaUtils.toJSONString(responseBean));
        return responseBean;
    }


    @PostMapping
    @Permission(
            code = "insert",
            name = "新增"
    )
    @GaeaAuditLog(
            pageTitle = "新增"
    )
    @Override
    public ResponseBean insert(@RequestBody HttpDirDto dto) {
        this.logger.info("{}新增服务开始，参数：{}", this.getClass().getSimpleName(), GaeaUtils.toJSONString(dto));
        HttpDirDto HttpDirDto = httpDirService.insertSet(dto);
        this.logger.info("{}新增服务结束，结果：{}", this.getClass().getSimpleName(), GaeaUtils.toJSONString(HttpDirDto));
        return ResponseBean.builder().data(HttpDirDto).build();
    }

    @PutMapping
    @Permission(
            code = "update",
            name = "更新"
    )
    @GaeaAuditLog(
            pageTitle = "修改"
    )
    @Override
    public ResponseBean update(@RequestBody HttpDirDto dto) {
        String username = UserContentHolder.getContext().getUsername();
        this.logger.info("{}更新服务开始,更新人：{}，参数：{}", this.getClass().getSimpleName(), username, GaeaUtils.toJSONString(dto));
        ResponseBean responseBean = this.responseSuccess();
        httpDirService.updateSet(dto);
        this.logger.info("{}更新服务结束，结果：{}", this.getClass().getSimpleName(), GaeaUtils.toJSONString(responseBean));
        return this.responseSuccess();
    }

    @DeleteMapping({"/{id}"})
    @Permission(
            code = "delete",
            name = "删除"
    )
    @GaeaAuditLog(
            pageTitle = "删除"
    )
    @Override
    public ResponseBean deleteById(@PathVariable("id") String id) {
        this.logger.info("{}删除服务开始，参数ID：{}", this.getClass().getSimpleName(), id);
        httpDirService.deleteSet(id);
        this.logger.info("{}删除服务结束", this.getClass().getSimpleName());
        return this.responseSuccess();
    }

    @GetMapping("/queryAll")
    public ResponseBean queryAll() {
    //查询所有
//        List<HttpDirDto> httpDirDtos = httpDirService.queryAllDirs();
        return ResponseBean.builder().data(httpDirService.queryAllDirs()).build();
    }
}
